<!DOCTYPE html>
<html>

<head>
    <title>北京站网格化系统</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Fonts -->
    <!-- CSS Libs -->
    <link rel="stylesheet" type="text/css" href="../lib/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="../lib/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="../lib/css/animate.min.css">
    <link rel="stylesheet" type="text/css" href="../lib/css/bootstrap-switch.min.css">
    <link rel="stylesheet" type="text/css" href="../lib/css/checkbox3.min.css">
    <link rel="stylesheet" type="text/css" href="../lib/css/jquery.dataTables.min.css">
    <link rel="stylesheet" type="text/css" href="../lib/css/dataTables.bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../lib/css/select2.min.css">
    <link rel="stylesheet" type="text/css" href="../lib/css/validform.min.css">
    <link rel="stylesheet" type="text/css" href="../lib/js/jquery-treegrid-master/jquery.treegrid.css">
    <!-- CSS App -->
    <link rel="stylesheet" type="text/css" href="../lib/css/common/style.css">
    <link rel="stylesheet" type="text/css" href="../lib/css/common/themes/flat-blue.css">
    <link rel="stylesheet" type="text/css" href="../lib/css/common/newstyle.css">
    <link rel="stylesheet" type="text/css" href="../lib/css/zc-common.css">
</head>

<body class="flat-blue">
    <div class="app-container expanded">
        <div class="row content-container">
            <nav class="navbar navbar-default navbar-fixed-top navbar-top">
                <div class="container-fluid app-header">
                    <div class="navbar-header">
                        <button type="button" class="navbar-expand-toggle fa-rotate-90">
                            <i class="fa fa-bars icon"></i>  
                        </button>
                        <top-nav></top-nav>
                    </div>
                    <right-info></right-info>
                </div>
            </nav>
            <div class="side-menu-wrap">
                <side-menu></side-menu>
            </div>
            <!-- Main Content -->
            <div class="container-fluid">
                <div class="side-body padding-top">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="card">
                                <div class="elm-wrap">
                                    <button type="button" onclick="editing('addInfo')" class="btn btn-info">添加类别</button>
                                </div>
                                <div class="elm-wrap">
                                    <table id="tb">
                                            
                                    </table>     
                                </div> 
                            </div>
                             
                        </div>   
                    </div>
                </div>
            </div>
        </div>
        <footer class="app-footer">
            <div class="wrapper"></div>
        </footer>
        <div class="modal fade" id="modalEdit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">添加子类别</h4>
                    </div>
                    <div class="modal-body">
                        <div class="" style="padding:5px;">
                            <form class="form-horizontal infoform">
                                    <div class="form-group">
                                        <label for="" class="col-sm-2 control-label">上级类别：</label>
                                        <div class="col-sm-10">
                                            <p class="form-control-static pinfotype">信息上报</p>
                                            <input type="hidden" value="" class="pid" name="pid">
                                            <input type="hidden" value="" class="did" name="did">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="" class="col-sm-2 control-label">类别名称：</label>
                                        <div class="col-sm-10">
                                            <input type="text" name="infotypename" class="form-control infotypename" id="" datatype="*" placeholder="请输入类别名称"  errormsg="请输入类别名称" nullmsg="请输入类别名称" >
                                            <span class='Validform_checktip'></span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="" class="col-sm-2 control-label">类别描述：</label>
                                        <div class="col-sm-10">
                                                <textarea class="form-control desc" rows="3" placeholder="不能超过100个字"></textarea>
                                        </div>
                                    </div>
                                </form>
                        </div>    
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-info" onclick="uploadData('editInfo')">确定</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="modalDel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel2">删除信息类别</h4>
                        <input type="hidden" value="" class="did" name="did">
                    </div>
                    <div class="modal-body">
                        确定信息类别吗？
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-info deling">确定</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="modalTips" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">
            <div class="modal-dialog modal-sm">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel3">提示</h4>
                    </div>
                    <div class="modal-body">
                        温馨提示
                    </div>
                </div>
            </div>
        </div>
    </div>
<!-- Javascript Libs -->
<script type="text/javascript" src="../lib/js/jquery.min.js"></script>
<script type="text/javascript" src="../lib/js/common/base.js"></script>
<script type="text/javascript" src="../lib/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../lib/js/bootstrap-switch.min.js"></script>
<script type="text/javascript" src="../lib/js/jquery.matchHeight-min.js"></script>
<script type="text/javascript" src="../lib/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../lib/js/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../lib/js/select2.full.min.js"></script>
<script type="text/javascript" src="../lib/js/validform.js"></script>
<script type="text/javascript" src="../lib/js/jquery-treegrid-master/jquery.treegrid.min.js"></script>
<script type="text/javascript" src="../lib/js/jquery-treegrid-master/jquery.treegrid.bootstrap3.js"></script>
<script type="text/javascript" src="../lib/js/jquery-treegrid-master/jquery.treegrid.extension.js"></script>
<script type="text/javascript" src="../lib/js/vue.js"></script>
<!-- <script type="text/javascript" src="../lib/js/ace/ace.js"></script>
<script type="text/javascript" src="../lib/js/ace/mode-html.js"></script>
<script type="text/javascript" src="../lib/js/ace/theme-github.js"></script> -->
<!-- Javascript -->
<script type="text/javascript" src="../lib/js/common/app.js"></script>
<script type="text/javascript">
    navData.accNav1 = 'info'
    navData.nav1Name = '信息管理'
    navData.accNav2 = 'info'
    navData.accNav3 = '9'
    var navVue = new Vue({
        el:'.side-menu-wrap' 
    })
    var navTopVue = new Vue({
        el:'.app-header' 
    })
    function initData(){
        $('#tb').treegridData({
            id: 'information_type_id',
            parentColumn: 'p_id',
            textColumn:'information_type_name',
            type: "POST", //请求数据的ajax类型
            url: serverUrl.base+serverUrl.informationType+'information_type_list',   //请求数据的ajax的url
            ajaxParams: {
                _:Math.random()
            }, //请求数据的ajax的data属性
            expandColumn: null,//在哪一列上面显示展开按钮
            striped: false,   //是否各行渐变色
            bordered: false,  //是否显示边框
            //expandAll: false,  //是否全部展开
            columns: [
                {
                    title: '信息名称',
                    field: 'information_type_name',
                    w:'80%',
                    exField:'information_type_desc'
                },
                {
                    title:'操作',
                    w:'20%',
                    style:{'text-align':'right'},
                    field:'',
                    html:function(item,tr){
                        var _text='<a class="" onclick="editing(\'editInfo\',this)" href="javascript:void(0)">编辑</a>'
                        if(item.p_id == '0'){
                            _text += ' | <a onclick="editing(\'addInfo\',this)" href="javascript:void(0)">添加子类别</a>'
                        }else{

                        }
                        if(item.information_type_id == '1' || item.information_type_id == '2' ){

                        }else{
                            _text += ' | <a class="" onclick="delingModal(\'infotype\',this)" href="javascript:void(0)">删除类别</a>'
                        }
                        
                        return _text
                    }
                }
            ],
            renderSuccess:function(){
                $('body').loading('close')
            },
            renderComplete:function(){
                $('body').loading('close')
                
            }
        });
    }
    initData()
    var Info={}
    function editing(type,evt){
        var elm=evt,name=type
        Info={}
        switch(name){
            case 'addInfo':case 'editInfo':
                Info = {
                    information_type_id:'',
                    p_id:'0',
                    information_type_name:'',
                    information_type_desc:''
                }
                var _text={
                    tit:'添加类别',
                    ptypeName:'信息上报'
                },$modal = $("#modalEdit")
                if(arguments[1] && name == 'addInfo'){
                    var _parenttr = $(elm).parents('tr'),$data = _parenttr.treegridData('getNodeData')
                    Info.p_id = $data.information_type_id
                    _text.tit = '添加子类别'
                    _text.ptypeName = $data.information_type_name
                }else if(arguments[1] && name == 'editInfo'){
                    var _parenttr = $(elm).parents('tr'),$pdata = _parenttr.treegridData('getParentNodeData'),$data = _parenttr.treegridData('getNodeData')
                    Info = $.extend({},Info,$data) 
                    if($pdata){
                        Info.p_id = $data.p_id
                        _text.ptypeName = $pdata.information_type_name
                    }
                    console.log(Info)
                    _text.tit = '编辑类别'
                    
                }else{
                }
                $('.infotypename').val(Info.information_type_name)
                $('.desc').val(Info.information_type_desc)
                $modal.find('.modal-title').text(_text.tit)
                $modal.find('.modal-body .pinfotype').text(_text.ptypeName)
                $modal.modal()
            break;

            default:
            break;
        }
        if(arguments[1]){
            if(name == 'train'){
                Info.rowData = elm
            }else{
                Info.row = $(elm).parents('tr')
            }
            
        }
        // var _type = type
        // var _this = evt || window.event.target
                        
        // var $modal = $("#modalEdit")
        // var $title =  $modal.find('.modal-title')
        // var $pDep =  $modal.find('.pdep')
        // var $pid =  $modal.find('.pid')
        // var $did =  $modal.find('.did')
        // var $depName =  $modal.find('.depname')
        // var $desc =  $modal.find('.desc')
        // var $depTypeWrap =  $modal.find('.deptype')
        // var _parenttr = $(_this).parents('tr')
        // var $pdata = _type != "devAddRoot"?_parenttr.treegridData('getParentNodeData'):{}
        // var $data = _type != "devAddRoot"?_parenttr.treegridData('getNodeData'):{workshop_id:1}

        // $pDep.text('北京铁路局北京火车站')

        // if(_type == "depAdd" || _type == "devAddRoot"){
        //     if(_type == "depAdd"){
        //         $title.text('添加子部门')
        //         $pid.val($data.department_id);
        //     }else{
        //         $title.text('添加部门')
        //         $pid.val(0);
        //     }
        //     if($data.p_id){
        //         $pDep.text($data.department_name)
        //     }
        //     $did.val('')
        //     $depTypeWrap.find('option[value=\''+$data.workshop_id+'\']').prop('selected',true)
        //     $depName.val('');
        //     $desc.val('');
        // }else if(_type == "depEdit"){
        //     $title.text('编辑部门')
        //     if($data.p_id){
        //         $pDep.text($pdata.department_name)
        //     }
        //     $depTypeWrap.find('option[value=\''+$data.workshop_id+'\']').prop('selected',true);
        //     $depName.val($data.department_name);
        //     $desc.val($data.department_desc);
        //     $pid.val($data.p_id);
        //     $did.val($data.department_id)
        // }
        
        // $("#modalEdit").modal()
    }
     //提交 
    function uploadData(name){
        switch(name){
            case 'editInfo':
            if(!myValidform.check()){
                return false
            }
            var $modal = $("#modalEdit")
            var upData={
                information_type_id:Info.information_type_id,
                p_id:Info.p_id,
                information_type_name:$modal.find('.infotypename').val(),
                information_type_desc:$modal.find('.desc').val()
            }
            $modal.loading('open')
            $.ajax({
                url:serverUrl.base+serverUrl.informationType+'edit_information_type',
                type:"POST",
                data:upData,
                dataType:"json",
                success:function(res){
                    if(res.code == '0'){
                        //更新表格
                        // _dataTable.settings()[0].ajax.data={'department_id':Info.department_id}
                        // _dataTable.ajax.reload()
                        var _info='',_tit='添加成功'
                        if(Info.row && Info.information_type_id != ''){
                            _info = '信息类别修改成功！'
                            _tit = '修改成功' 
                        }else if(Info.row && Info.information_type_id == ''){
                            _info = '二级信息类别添加成功！'
                        }else{
                            _info = '信息类别添加成功！'
                        }
                        
                        $("#modalTips").find('.modal-title').text(_tit) 
                        $("#modalTips").find('.modal-body').text(_info)
                        initData();
                        $('.card_edit').hide()
                        $('.card_list').show()
                    }else if(res.code == '2'){
                        $("#modalTips").find('.modal-title').text('出现问题') 
                        $("#modalTips").find('.modal-body').text(res.info)
                    }
                    setTimeout(function(){
                        $("#modalTips").modal()   
                        $("#modalTips").find('.modal-body').text(info) 
                    },500)
                },
                complete:function(res){
                    $("#modalEdit").modal('hide')
                    $modal.loading('close')
                },
                error:function(res){
                    $("#modalTips").find('.modal-title').text('出现问题') 
                    $("#modalTips").find('.modal-body').text(res.info)
                    setTimeout(function(){
                        $("#modalTips").modal()    
                    },500)
                }    
            })
            break;
        }
    }
    //删除
    function delingModal(name,elm){
        var _text={
            tit:'删除',
            body1:'确定删除吗？',
            body2:'删除出现问题',
            btn1:'确定',
            cbtn1:'取消',
            cbtn2:'知道了',
            deltit1:'删除成功',
            deltit2:'删除失败',
            delbody1:"删除成功！",
            delbody2:"出现问题",
        },_datas={
            id:'',
            data:{},
            url:''
        }
        switch(name){
            case 'infotype':
                if(arguments[1]){
                    Info = $(elm).parents('tr').treegridData('getNodeData')
                    console.log(Info)
                    _datas.data={
                        information_type_id:Info.information_type_id
                    }
                    _text.body1 = '确定删除该信息类别么？'
                }else{
                    
                }

                _datas.url = serverUrl.base+serverUrl.informationType+'del_information_type'
                _text.tit = '删除信息类别'
                $('#modalDel').find('.modal-title').text(_text.tit)
                $('#modalDel').find('.modal-body').text(_text.body1)
                $('#modalDel').modal()
            break;
            default:
            break;
        }
        $('.deling').off('click').on('click',function(){
            $.post(_datas.url,_datas.data,function(res){
                $('#modalDel').modal('hide')
                if(res.code == 0){
                    setTimeout(function(){
                        $('#modalTips').find('.modal-body').text(_text.deltit1)
                        $("#modalTips").modal()   
                        initData();
                    },500)
                    
                }else{
                    setTimeout(function(){
                        $('#modalTips').find('.modal-body').text(_text.deltit2)
                        $("#modalTips").modal()    
                    },500)
                }
            },'json').error(function(res){
                $('#modalDel').modal('hide')
                setTimeout(function(){
                    $('#modalTips').find('.modal-body').text(_text.delbody2)
                    $("#modalTips").modal()    
                },500)
            }).complete(function(){
                $('#modalDel').modal('hide')
            })
        })
        
    }   
    var myValidform = $(".infoform").Validform({
        tiptype:3
    });
</script>
</body>

</html>
